package com.changgou.system.service.impl;

import org.springframework.security.crypto.bcrypt.BCrypt;

/**
 * @author lqq
 * @date 2020-02-26 10:23
 */
public class TestBcrypt {
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            //获取盐
            String gensalt = BCrypt.gensalt();
            System.out.println("盐 = " + gensalt);
            //基于当前的盐,对密码进行加密
            //saltPassword为加密后得到的密文对象
            String saltPassword = BCrypt.hashpw("1234567", gensalt);
            System.out.println("加密后的密文 = " + saltPassword);


            //解密,输入密码进行加密后与密文对比,返回布尔值,true表示密码正确

            boolean checkpw = BCrypt.checkpw("1234567", saltPassword);
            System.out.println("checkpw = " + checkpw);
        }

    }
}
